﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;
using System.Web;

namespace GSMock.Resources
{
    public class FileBasedCacheManager
    {
        /// <summary>
        ///   The current web context.
        /// </summary>
        internal HttpContext HttpConext
        {
            get
            {
                return System.Web.HttpContext.Current;
            }
        }

        /// <summary>
        ///   Retrieves an object from cache.
        /// </summary>
        /// <param name="key">
        ///   The cache key.
        /// </param>
        /// <returns></returns>
        internal object GetFromCache(string key)
        {
            return this.HttpConext.Cache[key];
        }

        /// <summary>
        ///   Adds a cache object with a file based cache dependency.
        /// </summary>
        /// <param name="key">
        ///   The cache key.
        /// </param>
        /// <param name="value">
        ///   The value.
        /// </param>
        /// <param name="filePath">
        ///   The path to the source file used for the dependency.
        /// </param>
        internal void AddToCache(string key, object value, string filePath)
        {
            // Create the cache dependency.
            CacheDependency fileDependancy = new CacheDependency(filePath);

            // Add to cache.
            this.HttpConext.Cache.Insert(key, value, fileDependancy);
        }
    }
}
